package com.yiren.manager.service.impl.department;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrCgIndiServiceSendOrder;
import com.yiren.entity.YrCgissSalary;
import com.yiren.entity.YrElderArrearage;
import com.yiren.entity.YrElderPayRecord;
import com.yiren.entity.YrElderWallet;
import com.yiren.entity.YrIndiServiceCostRecord;
import com.yiren.manager.repository.cost.YrCgissSalaryRepository;
import com.yiren.manager.repository.cost.YrElderArrearageRepository;
import com.yiren.manager.repository.cost.YrElderPayRecordRepository;
import com.yiren.manager.repository.cost.YrIndiServiceCostRecordRepository;
import com.yiren.manager.repository.department.YrCgIndiServiceSendOrderRepository;
import com.yiren.manager.repository.elder.YrElderWalletRepository;
import com.yiren.manager.service.iface.cost.YrElderPayRecordService;
import com.yiren.manager.service.iface.department.YrCgIndiServiceSendOrderService;

@Service
public class YrCgIndiServiceSendOrderServiceImpl extends GenericServiceImpl<YrCgIndiServiceSendOrder, String> implements YrCgIndiServiceSendOrderService{

	@Autowired
	private YrElderArrearageRepository elderArrearageRepository;
	
	@Autowired
	private YrElderWalletRepository elderWalletRepository;
	
	@Autowired
	private YrElderPayRecordRepository elderPayRecordRepository;
	
	@Autowired
	private YrCgissSalaryRepository cgissSalaryRepository;
	
//	@Autowired
//	private YrIndiServiceCostRecordRepository indiServiceCostRecordRepository;
	
	@Autowired
	public YrCgIndiServiceSendOrderServiceImpl(YrCgIndiServiceSendOrderRepository repository) {
		super(repository);
	}

	@Transactional
	public void executefinish(Favorites entitys) throws MyException {
		YrCgIndiServiceSendOrder entity = entitys.getFavorite(YrCgIndiServiceSendOrder.class);
		YrElderWallet elderWallet = entitys.getFavorite(YrElderWallet.class);
		YrElderArrearage elderArrearage = entitys.getFavorite(YrElderArrearage.class);
//		YrIndiServiceCostRecord indiServiceCostRecord = entitys.getFavorite(YrIndiServiceCostRecord.class);
		YrElderPayRecord elderPayRecord = entitys.getFavorite(YrElderPayRecord.class);
		YrCgissSalary cgissSalary = entitys.getFavorite(YrCgissSalary.class);
		
		this.repository.save(entity);
		elderWalletRepository.save(elderWallet);
		if(null!= elderArrearage){
			elderArrearageRepository.save(elderArrearage);
		}
		if(null!=elderPayRecord){
			elderPayRecordRepository.save(elderPayRecord);
		}
		cgissSalaryRepository.save(cgissSalary);
		
	}

}
